<template>
  <div class="sort-bar">
    <el-button 
      size="small" 
      class="sort-btn"
      :class="{ active: currentSort === 'time' }"
      @click="handleSort('time')"
    >
      <i class="el-icon-date"></i> 时间排序
      <i :class="['el-icon-arrow-down', { 'is-reverse': sortOrder === 'desc' }]"></i>
    </el-button>
    <el-button 
      size="small" 
      class="sort-btn"
      :class="{ active: currentSort === 'level' }"
      @click="handleSort('level')"
    >
      <i class="el-icon-sort"></i> 等级排序
      <i :class="['el-icon-arrow-down', { 'is-reverse': sortOrder === 'desc' }]"></i>
    </el-button>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

const currentSort = ref('time')
const sortOrder = ref('desc')

const handleSort = (type) => {
  if (currentSort.value === type) {
    sortOrder.value = sortOrder.value === 'desc' ? 'asc' : 'desc'
  } else {
    currentSort.value = type
    sortOrder.value = 'desc'
  }
  
  ElMessage({
    message: `已按${type === 'time' ? '时间' : '等级'}${sortOrder.value === 'desc' ? '降序' : '升序'}排序`,
    type: 'success',
    duration: 1500
  })
}
</script>

<style scoped>
.sort-bar {
  margin-bottom: 24px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.sort-btn {
  background: linear-gradient(90deg, #eaf7e2 0%, #f0f9eb 100%);
  color: #7ac143;
  border: none;
  border-radius: 12px;
  font-weight: bold;
  padding: 8px 16px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(122, 193, 67, 0.1);
  white-space: nowrap;
}

.sort-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(122, 193, 67, 0.15);
  background: linear-gradient(90deg, #e0f5d0 0%, #e8f7e0 100%);
}

.sort-btn.active {
  background: linear-gradient(90deg, #7ac143 0%, #8edc5a 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(122, 193, 67, 0.2);
}

.sort-btn i {
  margin-right: 6px;
  transition: transform 0.3s ease;
}

.sort-btn i:last-child {
  margin-right: 0;
  margin-left: 4px;
}

.sort-btn:hover i:last-child {
  transform: translateY(2px);
}

.sort-btn .is-reverse {
  transform: rotate(180deg);
}

@media screen and (max-width: 768px) {
  .sort-bar {
    margin-bottom: 16px;
    gap: 8px;
  }

  .sort-btn {
    padding: 6px 12px;
    font-size: 14px;
  }
}
</style> 